using System;	
using System.Collections.Specialized;
using System.Data;

namespace SpringWaterDataAccess
{
	/// <summary>
	/// Summary description for Word.
	/// </summary>
	public class Word
	{
		public struct structRating
		{
			public int AverageScore;
			public int NumberOfVotes;
		}

		public enum enumScore
		{
			one = 1,
			two = 2,
			three = 3,
			four = 4,
			five= 5
		}

		#region Category
		public enum Category
		{
			topic1,
			topic2,
			topic3,
			topic4
		}
		#endregion

		#region PrivateMembers
		string		id;
		string		title;
		string		category;
		string		originAuthor;
		string		origin;
		string		url;
		int			rating;
		DateTime	createDate;
		string		createBy;
		string		editBy;
		DateTime	approveDate;
		string		approveBy;
		DateTime	lastModifyDate;
		string		lastModifyBy;
		DateTime	recommendDate;
		string		recommendBy;
		string		description;

		#endregion

		#region Constructors
		public Word(string ID)
		{
			id = ID;
		}
		public Word(string ID, string Title, string CommentID, string Author)
		{
			title = Title;
			id = ID;
			originAuthor = Author;
		}
		#endregion

		#region Properties Done
		public string Title
		{
			get{ return title;}
		}
		public string WordID
		{
			get {return id;}
		}
		public string WordCategory
		{
			get{return category;}
		}
		public string Origin
		{
			get{return origin;}
		}
		public string OriginAuthor
		{
			get { return originAuthor;}
		}
		public string URL
		{
			get{return url;}
		}
		public int Rating
		{
			get{return rating;}
		}
		public DateTime CreateDate
		{
			get{return createDate;}
		}
		public string CreateBy
		{
			get{return createBy;}
		}
		public string EditBy
		{
			get{return editBy;}
		}
		public DateTime ApproveDate
		{
			get{return approveDate;}
		}
		public string ApproveBy
		{
			get{return approveBy;}
		}
		public DateTime LastModifyDate
		{
			get{return lastModifyDate;}
		}
		public string LastModifyBy
		{
			get{return lastModifyBy;}
		}
		public DateTime RecommendDate
		{
			get{return recommendDate;}
		}
		public string RecommendBy
		{
			get{return recommendBy;}
		}
		public string Description
		{
			get{return description;}
		}

		public string Author
		{
			get{ return originAuthor;}
		}

		/// <summary>
		// return all the rating information for this word
		/// </summary>
		public structRating Rate
		{
			get 
			{ 
				structRating rate = new structRating();
				rate.AverageScore = 10;
				rate.NumberOfVotes = 10;
				return rate;
			}
		}
		#endregion

		#region Comments Done
		/// <summary>
		// add one comment for this word by user
		/// </summary>
		public bool AddComment(string subject, string comment, string email, string stars)
		{
			try
			{
				SQLAccess sql = new SQLAccess();
				sql.InsertComment(int.Parse(this.id), subject, comment, email, int.Parse(stars));
				return true;
			}
			catch(Exception e)
			{
				return false;
			}			
		}

		/// <summary>
		// return n comment starting from number start
		/// </summary>
		public DataSet GetComments(int start, int n)
		{
			try
			{
				SQLAccess sql = new SQLAccess();
				DataSet ds = sql.RetrieveComments(int.Parse(this.id), start,n);
				if (ds.Tables.Count== 0 || ds.Tables[0].Rows.Count == 0)
					return null;
				else
					return ds;
			}
			catch(Exception e)
			{
				return null;
			}			
		}
		/// <summary>
		// delete one comment for this word by user
		/// </summary>
		public bool DeleteComment(int commentID)
		{
			try
			{
				SQLAccess sql = new SQLAccess();
				sql.DeleteComment(int.Parse(this.id), commentID);
				return true;
			}
			catch(Exception e)
			{
				return false;
			}			
		}

		/// <summary>
		// add one rating to this word by user
		/// </summary>
		public bool AddRating(enumScore score, string email)
		{
			return true;
		}
		#endregion
	}

}
